﻿using System;
using System.Collections.Generic;
using OhioState.Graphics.Proxy;
using OhioState.AssetManaged;

namespace OhioState.Graphics.OpenGL
{
    public class ModelHandler : OpenGLObject, IDrawable
    {
        public ModelHandler(ModelProxy proxy)
            : base(proxy)
        {
        }

        #region IDrawable Members
        public IBoundingVolume BoundingVolume
        {
            get;
            private set;
        }

        public IMaterial Material
        {
            get;
            set;
        }

        public void Render(IRenderPanel panel)
        {
            if (!created)
                Create(panel);

            realModel.Render(panel);
        }

        #endregion

        private void Create(IRenderPanel panel)
        {
            ModelProxy model = proxyObject as ModelProxy;
            float[] vertices = model.Vertices;
            float[] textureCoords = model.TextureCoordinates;
            //int[] indices = model.Indices;
            realModel = new ModelGL(vertices, textureCoords); //, indices);
            realModel.Material = panel.ResourceManager.GetItem(model.Material as IAssetManaged) as IMaterial;
            created = true;
        }

        ModelGL realModel;
        private bool created = false;
    }
}
